package com.yjpark;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.widget.ImageView;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
    // thumbnail
    private static int TAKE_PICTURE = 1;
    public void onPictureClick(View view) {
    	Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    	startActivityForResult(intent, TAKE_PICTURE);
    	
    }
    
    // Full
    private Uri outputFileUri;
    public void onPictureClick2(View view) {
    	Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    	File file = new File(Environment.getExternalStorageDirectory(), "sample.jpg");
    	outputFileUri = Uri.fromFile(file);
    	intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);    	
    	startActivityForResult(intent, TAKE_PICTURE);
    	
    }
    
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		
		if(requestCode == TAKE_PICTURE) {
			if(data != null) {
				if(data.hasExtra("data")) {
					Bitmap thumbnail = data.getParcelableExtra("data");
					ImageView imgView = (ImageView)findViewById(R.id.imageView1);
					imgView.setImageBitmap(thumbnail);
					// thumbmail
				}
			} 
		} else {
			ImageView imgView = (ImageView)findViewById(R.id.imageView1);
			imgView.setImageURI(outputFileUri);
			// Full
		}
	}
}